package com.dyit.service.impl;

import com.dyit.dao.IBookDao;
import com.dyit.service.IBookService;
import com.dyit.vo.BookVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class BookServiceImpl implements IBookService {
    @Autowired
    private IBookDao ibd;
    @Override
    public List<BookVo> countBookByCategory() {
        List<String> categoryList = ibd.findAllCategory();

        List<BookVo> listVo = new ArrayList<>();
        int i=0;
        while (!categoryList.isEmpty()){
             String category=categoryList.get(i);
            listVo.add(new BookVo(category, ibd.countAllByCategory(category)));
            categoryList.remove(i);
        }
        return listVo;
    }


}
